'use strict';
var Clipboard = require('clipboard');
/////////////////////////////////////
//公共指令
//v2 2018年3月16日 10:30:20
/////////////////////////////////////
function clipboard($http, $timeout, $alert) {
    return {
        restrict: 'EA',
        scope: { ngModel: '=' },
        link: function (scope, element, attributes) {
            function initClip( element ){
                var clipboard2 = new Clipboard( element[0] );
                clipboard2.on('success', function(e) {
                    console.info("复制文本",e.text);
                    $alert.success( "复制成功" );
                    //layer.alert( "复制成功" , {title:"成功信息",icon: 1}, function(index){ layer.close(index) });
                });
                clipboard2.on('error', function(e) { });
            }
            element.attr( "data-clipboard-text", scope.ngModel );
            scope.$watch("ngModel",function(newValue){
                element.attr( "data-clipboard-text", newValue );
            });
            initClip( element );
        }
    };
}
exports = module.exports = clipboard;